package com.example.component;

import cn.dev33.satoken.stp.StpInterface;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.example.mapper.UserMapper;
import com.example.model.UserDO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

/*
 * 自定义权限验证接口扩展
 */
@Component
public class StpInterfaceImpl implements StpInterface {
    @Autowired
    private UserMapper userMapper;

    // 返回一个账号所拥有的权限码集合
    @Override
    public List<String> getPermissionList(Object o, String s) {
        return null;
    }

    // 返回一个账号所拥有的角色标识集合 (权限与角色可分开校验)
    @Override
    public List<String> getRoleList(Object loginId, String loginType) {
        UserDO userDO = userMapper.selectOne(new QueryWrapper<UserDO>().eq("id", loginId));

        List<String> roleList = new ArrayList<>();
        roleList.add(userDO.getRole());

        return roleList;
    }
}
